package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.model.domain.SmsHomeBrand;
import com.mall.model.vo.PageResult;
import com.mall.service.marketing.mapper.SmsHomeBrandMapper;
import com.mall.service.marketing.service.SmsHomeBrandService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsHomeBrandServiceImpl extends ServiceImpl<SmsHomeBrandMapper, SmsHomeBrand> implements SmsHomeBrandService{

    @Autowired
    private SmsHomeBrandMapper smsHomeBrandMapper;

    //分页查询推荐品牌
    @Override
    public PageResult findList(String brandName, Integer recommendStatus, Integer pageNum, Integer pageSize) {
        Page<SmsHomeBrand> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsHomeBrand> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(brandName)){
            queryWrapper.like(SmsHomeBrand::getBrandName,brandName);
        }
        if (recommendStatus != null){
            queryWrapper.eq(SmsHomeBrand::getRecommendStatus,recommendStatus);
        }
        Page<SmsHomeBrand> smsHomeBrandPage = smsHomeBrandMapper.selectPage(page, queryWrapper);

        return new PageResult(pageNum,pageSize, (int) smsHomeBrandPage.getTotal(),smsHomeBrandPage.getRecords());
    }


}
